var phone="";
var yanzhengma=0;
var passWord01="";






let isQrLogin = false;

function showSmsLogin() {
    document.getElementById('sms-login').classList.add('active');
    document.getElementById('password-login').classList.remove('active');
    document.getElementById('qr-login').classList.remove('active');
}

function showPasswordLogin() {
    document.getElementById('sms-login').classList.remove('active');
    document.getElementById('password-login').classList.add('active');
    document.getElementById('qr-login').classList.remove('active');
}

function toggleLogin() {
    if (isQrLogin) {
        showSmsLogin();
    } else {
        document.getElementById('sms-login').classList.remove('active');
        document.getElementById('password-login').classList.remove('active');
        document.getElementById('qr-login').classList.add('active');
    }
    isQrLogin = !isQrLogin;
    document.getElementById('sms-login').style.display = 'none';
    document.getElementById('password-login').style.display = 'block';
}

document.addEventListener('DOMContentLoaded', function () {
    showSmsLogin();
});

let timer;
const TIME_LIMIT = 60; // 秒
let timeLeft = TIME_LIMIT;

function sendSms() {
    const button = document.querySelector('#sms-login button[type="button"]');
    if (timer) return; // 如果定时器还在运行，则不允许再次发送

    // 初始化计时器
    timeLeft = TIME_LIMIT;
    button.disabled = true;
    button.textContent = `发送验证码 (${timeLeft}s)`;
    timer = setInterval(() => {
        timeLeft -= 1;
        if (timeLeft <= 0) {
            clearInterval(timer);
            timer = null;
            button.disabled = false;
            button.textContent = '发送验证码';
        } else {
            button.textContent = `发送验证码 (${timeLeft}s)`;
        }
    }, 1000);

    var phone = document.getElementById('phone').value;
    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'phoneServlet', true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.onload = function () {
        if (xhr.status === 200) {
            var response = JSON.parse(xhr.responseText);
            // 处理服务器响应
        }
    };
    xhr.send('phone=' + encodeURIComponent(phone));
}

document.getElementById('sms-form').addEventListener('submit', function(event) {
    event.preventDefault();
    sendSms();
});
//表单验证
